package com.fenqing.leetcode.code.t0_200.t100_200;

import com.fenqing.annotations.Execute;
import com.fenqing.core.Topic;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Topic136_2 extends Topic {
    /**
     * 构造器
     *
     * @param input 输入
     */
    public Topic136_2(String input) {
        super(input);
    }

    @Execute
    public int singleNumber(int[] nums) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            int count = map.getOrDefault(num, 0);
            map.put(num, count + 1);
        }
        Set<Map.Entry<Integer, Integer>> entries = map.entrySet();
        for (Map.Entry<Integer, Integer> entry : entries) {
            Integer value = entry.getValue();
            if (value == 1) {
                return entry.getKey();
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        Topic136_1 topic136 = new Topic136_1("""
                [2,2,1]
                """);
        int run = topic136.run();
        System.out.println(run);
    }
}
